package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPositionsAvailable;
import com.ruoyi.system.service.ISysPositionsAvailableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 招聘岗位信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-16
 */
@RestController
@RequestMapping("/system/available")
public class SysPositionsAvailableController extends BaseController
{
    @Autowired
    private ISysPositionsAvailableService sysPositionsAvailableService;

    /**
     * 查询招聘岗位信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:available:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPositionsAvailable sysPositionsAvailable)
    {
        startPage();
        List<SysPositionsAvailable> list = sysPositionsAvailableService.selectSysPositionsAvailableList(sysPositionsAvailable);
        return getDataTable(list);
    }

    /**
     * 导出招聘岗位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:available:export')")
    @Log(title = "招聘岗位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPositionsAvailable sysPositionsAvailable)
    {
        List<SysPositionsAvailable> list = sysPositionsAvailableService.selectSysPositionsAvailableList(sysPositionsAvailable);
        ExcelUtil<SysPositionsAvailable> util = new ExcelUtil<SysPositionsAvailable>(SysPositionsAvailable.class);
        util.exportExcel(response, list, "招聘岗位信息数据");
    }

    /**
     * 获取招聘岗位信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:available:query')")
    @GetMapping(value = "/{positionCode}")
    public AjaxResult getInfo(@PathVariable("positionCode") String positionCode)
    {
        SysPositionsAvailable s=sysPositionsAvailableService.selectSysPositionsAvailableByPositionCode(positionCode);
        return success(sysPositionsAvailableService.selectSysPositionsAvailableByPositionCode(positionCode));
    }

    /**
     * 新增招聘岗位信息
     */
    @PreAuthorize("@ss.hasPermi('system:available:add')")
    @Log(title = "招聘岗位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPositionsAvailable sysPositionsAvailable)
    {
        return toAjax(sysPositionsAvailableService.insertSysPositionsAvailable(sysPositionsAvailable));
    }

    /**
     * 修改招聘岗位信息
     */
    @PreAuthorize("@ss.hasPermi('system:available:edit')")
    @Log(title = "招聘岗位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPositionsAvailable sysPositionsAvailable)
    {
        return toAjax(sysPositionsAvailableService.updateSysPositionsAvailable(sysPositionsAvailable));
    }

    /**
     * 删除招聘岗位信息
     */
    @PreAuthorize("@ss.hasPermi('system:available:remove')")
    @Log(title = "招聘岗位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{positionIds}")
    public AjaxResult remove(@PathVariable Long[] positionIds)
    {
        return toAjax(sysPositionsAvailableService.deleteSysPositionsAvailableByPositionIds(positionIds));
    }

    /**
     * 下载招聘岗位信息模板
     */
    @PreAuthorize("@ss.hasPermi('system:available:import')")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<SysPositionsAvailable> util = new ExcelUtil<>(SysPositionsAvailable.class);
        util.importTemplateExcel(response, "招聘岗位信息模板");
    }

    /**
     * 导入招聘岗位信息
     */
    @Log(title = "招聘岗位管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:available:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<SysPositionsAvailable> util = new ExcelUtil<SysPositionsAvailable>(SysPositionsAvailable.class);
        List<SysPositionsAvailable> positionsavailableList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = sysPositionsAvailableService.importPositionsAvailable(positionsavailableList, updateSupport, operName);
        return success(message);
    }

}
